# 运行此代码初始化摄像头
import sensor, image, time
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.set_auto_whitebal(False)
sensor.set_auto_gain(False)
sensor.set_auto_exposure(False, exposure_us=10000)  # 固定曝光
# 使用此代码验证蓝色检测
blue_thresh = (30, 70, -20, 20, -70, -20)  # 示例阈值
#blue_thresh = (47, 71, -27, 4, -71, -31)


while True:
    img = sensor.snapshot()
    blobs = img.find_blobs([blue_thresh],
        area_threshold=1500, merge=True)

    if blobs:
        b = max(blobs, key=lambda x:x.area())
        img.draw_rectangle(b.rect(), color=(0,0,255))
        img.draw_string(b.x(), b.y(),
            f"B:{b.cx()},{b.cy()}",
            color=(255,255,0))
